home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / cc04.arc / YARCHIVE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1986-03-15  |  15.1 KB  |  710 lines

  1. /*
  2.     NetWare Alloy Archive Utility (Front-End Procedures)
  3.     V4.42    02/04/84    by Mark Hurst
  4.  
  5.     For use with NetWare V4.n Systems
  6.  
  7.     Copyright (C) 1983, 1984 Novell, Inc.
  8. */
  9.  
  10. #include    "ctype.h"
  11. #include    "stdio.h"
  12.  
  13.  
  14. #define LOCALBIT    0x80
  15. #define    PERMNET        0x01
  16. #define    TEMPNET        0x02
  17. #define    NETBITS        0x03
  18.  
  19. #define    READBIT        0x01
  20. #define    WRITEBIT    0x02
  21. #define    OPENBIT        0x04
  22. #define    CREATEBIT    0x08
  23. #define    DELETEBIT    0x10
  24. #define    OWNEDBIT    0x20
  25. #define    SEARCHBIT    0x40
  26. #define    MODIFYBIT    0x80
  27.  
  28. /* NOTE: the Archive bit was 0x80 on ShareNet V3.12.  Has now changed: */
  29. #define BACKUPBIT    0x20
  30.  
  31. static    char    author[] = 
  32. "Author: Mark Hurst of SuperSet Software Corp.  Copyright (C) 1984";
  33.  
  34. unsigned DOS11, DOS20;
  35.  
  36. struct    volstruct {
  37.     unsigned    SecPerBlock;
  38.     unsigned    TotalBlocks;
  39.     unsigned    UnusedBlocks;
  40.     unsigned    TotalDir;
  41.     unsigned    UnusedDir;
  42.     char        vol_name[16];
  43.     unsigned    remove;
  44. } volinfo2;
  45.  
  46.  
  47. #define        VARPATH        '^' - 'A'
  48.  
  49. #define        TRUE        1
  50. #define        FALSE        0
  51.  
  52. #define        MAXVOLUMES    16
  53. #define        MAXSPECS    100
  54.  
  55. #define        ALLMODE        1
  56. #define        MODMODE        2
  57. #define        SELMODE        3
  58.  
  59. int    printlog, spool;
  60.  
  61. char    actarget[20];
  62.  
  63. int    startup;
  64.  
  65. extern    unsigned fileswritten;
  66.  
  67. int    system, continuous, finclude, fexclude;
  68. char    *speclist[MAXSPECS];
  69. int    speccount;
  70.  
  71. int    savestate, dontask;
  72.  
  73. int    numberqualified, numberout;
  74. char    *calloc(), *malloc();
  75.  
  76. unsigned known, firsttypecheck, unusabledisk;
  77.  
  78. extern    struct    dirret {
  79.     int    maxlen;
  80.     char    subname[16];
  81.     char    createtime[4];
  82.     char    user_unique[4];
  83.     char    mask;
  84.     char    pad_junk;
  85.     int    subnum;
  86. } subinfo;
  87.  
  88. typedef struct dosfcb {
  89.     char    drive;
  90.     char    fname[8];
  91.     char    fext[3];
  92.     unsigned curblk;
  93.     unsigned recsize;
  94.     long    size;
  95.     unsigned date;
  96.     char    reserved[10];
  97.     char    relrec;
  98.     char    record[4];
  99. } FCB;
  100.  
  101. typedef    struct exdirfcb {
  102.     char    dummy;
  103.     char    exset;
  104.     char    res[5];
  105.     char    flags;
  106.     char    drive;
  107.     char    fname[8];
  108.     char    fext[3];
  109.     char    gap[17];
  110.     char    size[4];
  111. } ExDirFCB;
  112.  
  113. typedef struct exdosfcb {
  114.     char    dummy;
  115.     char    exset;
  116.     char    res[5];
  117.     char    flags;
  118.     char    drive;
  119.     char    fname[8];
  120.     char    fext[3];
  121.     unsigned curblk;
  122.     unsigned recsize;
  123.     long    size;
  124.     unsigned date;
  125.     char    reserved[10];
  126.     char    relrec;
  127.     char    record[4];
  128. } ExFCB;
  129.  
  130. int    mode, bdrive, firstcopy;
  131.  
  132. char    pathstring[256];
  133. char    privmask;
  134.  
  135. int    listcount;
  136. typedef    struct    liststruct {
  137.     struct liststruct *link;
  138.     char    name[12]; /* 1 too big for even allocation */
  139.     char    marked;
  140.     char    flags;
  141.     long    size;    /* size of file in bytes */
  142.     unsigned units;    /* size of file in allocation units */
  143. } LISTNODE;
  144.  
  145. #define     LISTSIZE    250
  146. LISTNODE *list[LISTSIZE], *curnode;
  147.  
  148. int    saverights;
  149. int    logexists; /* flag; TRUE means there is an existing log file */
  150. extern    FCB    logfcb;
  151. extern    int    BrkFlag;
  152.  
  153. int    imin();
  154. unsigned umin();
  155. long    lmin();
  156.  
  157. abort()
  158. {
  159.     cprintf("\r\n\7Archive session terminated.\r\n");
  160.     if (printlog) {
  161.         prnline(); 
  162.         printstr("ARCHIVE SESSION CANCELLED\r\n"); 
  163.         prnline();
  164.     }
  165.     myexit(0);
  166. }
  167.  
  168. checkbreak()
  169. {
  170.     char    ch;
  171.     ChkKey();
  172.     if (BrkFlag) {
  173.         cprintf("\r\n\7");
  174.         if (yes("Cancel Archive session? (Y/N) ")) {
  175.             abort();
  176.         }
  177.         BrkFlag = 0;
  178.     }
  179. }
  180.  
  181. myexit(exitcode)
  182. int    exitcode;
  183. {
  184.     if (printlog) {
  185.         printstr("\r\n\r\n");
  186.         prnline();
  187.         printstr("END OF ARCHIVE LOG REPORT\r\n");
  188.         prnline();
  189.     }
  190.     modLST(1); /* restore LST: to local and signal spooler to print */
  191.     rewindtape();
  192.     exit(exitcode);
  193. }
  194.  
  195. /* FATAL ERROR REPORTING ROUTINE */
  196. error(message)
  197. char    *message;
  198. {
  199.     cprintf("FATAL ERROR: %s\7\r\n", message);
  200.     if (printlog) {
  201.         prnline();
  202.         printstr("FATAL ERROR: "); printstr(message); printstr("\r\n");
  203.         prnline();
  204.     }
  205. }
  206.  
  207. extern    char    inline[];
  208.  
  209.  
  210. showsub (level)
  211.     int    level;
  212. {
  213.     int    i, spaces;
  214.     char    nextlevel[18];
  215.  
  216.     i = 1;
  217.     while(getsubinfo(VARPATH, i) == 0) {
  218.         /* got a subdirectory */
  219.         i = subinfo.subnum + 1;
  220.         subinfo.subname[15] = 0;
  221.         pathmodset (VARPATH, VARPATH, subinfo.subname); /* drop to next sub level */
  222.  
  223.         /* BACKUP UP THIS PARTICULAR DIRECTORY */
  224.         backupdir();
  225.  
  226.         /* BACKUP NEXT LAYER DOWN IN THE DIRECTORY HIERARCHY */
  227.         showsub (level + 1);
  228.         pathmodset (VARPATH, VARPATH, "..");  /*come back to my level*/
  229.     }
  230.     return (i-1);
  231. }
  232.  
  233.  
  234. showroot (line)
  235.     char    *line;
  236. {
  237.     firstpath (line);
  238.     if (startup) {
  239.         setup(); 
  240.         startup = FALSE; 
  241.         configlog(); 
  242.         tapesetup();
  243.         if (savestate) ssave ();
  244.     }
  245.  
  246.     /* BACKUP UP THIS ROOT */
  247.     backupdir();
  248.  
  249.     /* do subdirectories now */
  250.     showsub (1);
  251. }
  252.  
  253.  
  254. setup()
  255. {
  256.     privmask = READBIT | SEARCHBIT | OPENBIT | MODIFYBIT;
  257.  
  258.     if (dontask == FALSE) {
  259.         if (!yes ("Do you want to save directory rights and trustee lists? (Y/N) ")) 
  260.              saverights = FALSE;
  261.         else saverights = TRUE;
  262.         ssquery ();
  263.     }
  264.  
  265.     if (yes(
  266. "Do you want the specified directories to be scanned w/out interruption? (Y/N) ")) {
  267.         continuous = TRUE;
  268.         mode = 0;
  269.         cprintf("Select backup mode for ALL directories from following:\r\n");
  270.         cprintf("     1) Backup ALL qualified files in each directory\r\n");
  271.         cprintf("     2) Backup ONLY qualified files that have been modified since last backup\r\n");
  272.         cprintf("\r\n");
  273.         while (mode != ALLMODE && mode != MODMODE) {
  274.             cprintf("Select Option: (1, 2) ");
  275.             mode = getstr(inline, 1);
  276.             if (mode == 0x03) abort();
  277.             mode = mode - '0'; 
  278.             cprintf("\r\n");
  279.         }
  280.         inexquery();
  281.     }
  282.     else continuous = FALSE;
  283. }
  284.  
  285. backupdir()
  286. {
  287.     checkbreak(); /* check for ^C or ^S as each directory is checked */
  288.     getcurpath (VARPATH, pathstring);
  289.     if (!checkrights(VARPATH, privmask)) {
  290.         if (printlog) printstr("\r\n");
  291.         lprint(pathstring);
  292.         lprint("\r\n     No backup privileges.\r\n");
  293.         return;
  294.     }
  295.  
  296.     /* INITIALIZE LIST POINTER ARRAY FOR LIST OF FILES TO BACKUP */
  297.     setmem(list,LISTSIZE*2, 0);
  298.     listcount = 0;
  299.  
  300.     /* DO BACKUP OF DIRECTORY */
  301.     scandir();
  302. }
  303.  
  304. static    char    *badnames[] = {"CON", "AUX", "COM1", "LPT1", "PRN", "NUL", 0};
  305.  
  306. badname(f)
  307. ExDirFCB    *f;
  308. {
  309.     int    i, j, match;
  310.     char    *s;
  311.  
  312.     i = 0;
  313.     while (badnames[i]) {
  314.         s = badnames[i++];
  315.         match = TRUE;
  316.         for (j=0; j < strlen(s) && match; j++) {
  317.             if (s[j] != f->fname[j]) match = FALSE;
  318.         }
  319.         if (match) {
  320.             if (f->fname[j] == 0x20) return (TRUE); /* BAD NAME */
  321.         }
  322.     }
  323.     return (FALSE);
  324. }
  325.  
  326. scandir()
  327. {
  328.     ExFCB    search, file;
  329.     ExDirFCB    *dfile;
  330.     char    ch;
  331.     int    ccode;
  332.  
  333.     setmem(&search, sizeof(ExFCB), 0);
  334.     setmem(search.fname, 11, '?');
  335.     search.drive = VARPATH + 1;
  336.     search.exset = 0xFF;
  337.     search.flags = 0x02 | 0x04; /* PULL IN HIDDEN AND SYS FILES ALSO */
  338.     dfile = (ExDirFCB *)&file;
  339.     setDTA(&dfile->exset);
  340.  
  341.     ccode = search1(&search.exset);
  342.  
  343.     if (printlog) printstr("\r\n");
  344.     lprint(pathstring);
  345.     lprint("\r\n");
  346.  
  347.     while (ccode == 0 && badname(dfile)) ccode = searchn(&search.exset);
  348.     if (!saverights) {
  349.         if (ccode) {
  350.             lprint ("     No files.\r\n");
  351.             return;
  352.         }
  353.     }
  354.  
  355.     if (!continuous) {
  356.         if (ccode) { /* no files */
  357.             if (saverights) {
  358.             cprintf ("     There are no files in this directory.\r\n");
  359.             if (!yes(
  360. "     Do you still want to backup the directory rights and trustees? (Y/N) ")) {
  361.                 if (printlog) {
  362.                     printstr (
  363. "     No files.  User chose NOT to archive directory rights and trustees.\r\n");
  364.                 }
  365.                 return;
  366.             }
  367.             }
  368.         }
  369.         else {
  370.             if (!yes("     Backup? (Y/N) ")) {
  371.             if (printlog) printstr(saverights ?
  372.         "     User chose not to archive this directory's rights, trustees, or files.\r\n"
  373.           : "     User chose not to archive files from this directory.\r\n");
  374.             return;
  375.             }
  376.         }
  377.  
  378.         if (ccode) goto doscan;
  379.  
  380.         mode = 0;
  381.         cprintf("Select backup mode for this directory from following:\r\n");
  382.         cprintf(
  383. "     1) Backup ALL qualified files in each directory\r\n");
  384.         cprintf(
  385. "     2) Backup ONLY qualified files that have been modified since last backup\r\n");
  386.         cprintf(
  387. "     3) Choose specific files during directory scan\r\n");
  388.         cprintf("\r\n");
  389.         while (mode < 1 || mode > 3) {
  390.             cprintf("Select Option: (1-3) ");
  391.             mode = getstr(inline, 1);
  392.             if (mode == 0x03) abort();
  393.             mode -= '0';
  394.             cprintf("\r\n");
  395.         }
  396.         if (mode == ALLMODE || mode == MODMODE) inexquery();
  397.     }
  398.  
  399. doscan:
  400.     /* DO DIRECTORY SCAN */
  401.     numberout = numberqualified = 0;
  402.     if (saverights) AddTrustFile ();
  403.  
  404.     while (ccode == 0) {
  405.         if (!badname(dfile)) {
  406.             if (verify(dfile)) addtolist(dfile);
  407.             if (listcount == LISTSIZE) writelist();
  408.         }
  409.         setDTA(&dfile->exset);
  410.         ccode = searchn(&search.exset);
  411.     }
  412.     writelist();
  413.  
  414.     if (mode == MODMODE && !numberqualified) {
  415.         lprint(
  416. "     No files in this directory changed since they were last archived.\r\n");
  417.     }
  418.  
  419.     if (numberout == 0) {
  420.         lprint("     No files archived from this directory.\r\n");
  421.     }
  422. }
  423.  
  424. verify(file)
  425. ExDirFCB    *file;
  426. {
  427.     int    ret;
  428.     ret = xverify(file);
  429.     if (ret) numberqualified++;
  430.     return (ret);
  431. }
  432.  
  433. xverify(file)
  434. ExDirFCB    *file;
  435. {
  436.     char    ch, f[15];
  437.  
  438.     /* CHECK FOR SPECIAL NETWORK FILES IN SUPERVISOR DIR AND IGNORE THEM */
  439.     if (strcmp("SYS:SUPER", pathstring) == 0) {
  440.         movmem(file->fname, f, 11);
  441.         f[11] = 0;
  442.         if (f[0] == 'S' && f[1] == 'P' && f[2] == 'L' &&
  443.             f[5] == '$') return (FALSE);
  444.         if (!strcmp(f, "NET$SPL QUE")) return (FALSE);
  445.         if (!strcmp(f, "NET$MSG SYS")) return (FALSE);
  446.     }
  447.  
  448.     switch(mode) {
  449.     case SELMODE: /* Select files */
  450.         cprintf("     ");
  451.         showfile(&file->drive);
  452.         if (yes(" Backup? (Y/N) ")) return (TRUE);
  453.         else return (FALSE);
  454.         break;
  455.     case ALLMODE: /* Accept all files for backup */
  456.         if (exclude(file->fname)) return (FALSE);
  457.         if (!include(file->fname)) return (FALSE);
  458.         return (TRUE);
  459.         break;
  460.     case MODMODE: /* Backup ONLY files changed since last backup */
  461.         if (exclude(file->fname)) return (FALSE);
  462.         if (!include(file->fname)) return (FALSE);
  463.         if (file->gap[0] & BACKUPBIT) return (TRUE);
  464.         else return (FALSE);
  465.         break;
  466.     }
  467. }
  468.  
  469.  
  470. addtolist(file)
  471. ExDirFCB    *file;
  472. {
  473.     curnode = (LISTNODE *) calloc(1, sizeof(LISTNODE));
  474.     list[listcount++] = curnode;
  475.     movmem(file->fname, curnode->name, 11);
  476.     curnode->marked = 0; /* clear MARKED flag */
  477.     curnode->flags = file->gap[0];
  478.     movmem(file->size, &curnode->size, 4);
  479.     curnode->units = 0;
  480. }
  481.  
  482.  
  483. _main(line)
  484. char    *line;
  485. {
  486.     int    i;
  487.  
  488.     conupper (++line);
  489.     compress(line);
  490.     cpmoff(); /* set network interface shell to really close files */
  491.     trapbreak(); /* stop DOS from aborting */
  492.     main(line);
  493.     cprintf("\r\nArchive Session Completed.");
  494.     myexit(0);
  495. }
  496.  
  497.  
  498. main(l)
  499. char    *l;
  500. {
  501.     int    ccode, root, colpos, len;
  502.     char    line[256], dd[4];
  503.     unsigned OS, major, minor;
  504.  
  505.     DOS20 = DOS11 = FALSE;
  506.  
  507.     OS = GVersionNumber();
  508.     major = (OS & 0x00FF);
  509.     minor = (OS & 0xFF00) >> 8;
  510.     if (major < 2) DOS11 = TRUE; /* REPRESENT DOS v1.1 */
  511.     else if (major == 2) DOS20 = TRUE; /* REPRESENT DOS v2.0 */
  512.  
  513.  
  514.     cprintf("TARCHIVE V4.42 BETA -- Archive to Alloy Tape \r\n");
  515.     cprintf("Copyright (C) 1983, 1984 by Novell, Inc.\r\n\r\n");
  516.  
  517.     /* Save current mapping for fourth network drive to be used as temp */
  518.     finclude, fexclude = FALSE; /* initialize no special inc or excs */
  519.     printlog, spool = FALSE;
  520.     firsttypecheck = TRUE;
  521.     savestate = FALSE;
  522.  
  523.     setmem(&list[0], LISTSIZE * 2, 0x00); /* CLEAR LIST NODE POINTERS */
  524.  
  525.     startup = TRUE; /* this flag is checked in 'showroot()', where
  526.             the user is asked all the set up questions
  527.             only after we know his specified path domain is OK */
  528.  
  529.     if (!strcmp("SYSTEM", l)) {
  530.         cprintf (
  531. "\r\nIMPORTANT:  When making a system backup, it is vitally important that the\r\n");
  532.         cprintf (
  533. "system files NET$PASS.SYS and NET$GRP.SYS in SYS:SUPER be saved.  These files\r\n");
  534.         cprintf (
  535. "completely define the identity of all users and groups on this file server.\r\n");
  536.         cprintf (
  537. "These files will be archived automatically when this archive session commences.\r\n");
  538.         cprintf (
  539. "     Every directory archived during this session will have its rights and\r\n");
  540.         cprintf (
  541. "list of trustees saved for use in a full system restore.\r\n\r\n");
  542.         cprintf (
  543. "     You MUST login as the real SUPERVISOR user in order to guarantee that a\r\n");
  544.         cprintf (
  545. "complete system backup will be made.  If you are not logged in as SUPERVISOR,\r\n");
  546.         cprintf (
  547. "press ^C at the next question to exit.\r\n");
  548.  
  549.         savestate = TRUE;
  550.         saverights = TRUE;
  551.         dontask = TRUE;
  552.         system = TRUE;
  553.         getvollist();
  554.         backupsys();
  555.         return;
  556.     }
  557.     else system = FALSE;
  558.  
  559.     dontask = FALSE;
  560.  
  561.     strcpy(line, l);
  562.     showroot(line);
  563. }
  564.  
  565.  
  566. ssquery ()
  567. {
  568.     if (!yes 
  569. ("Do you want to archive the system's user and group definitions? (Y/N) "))
  570.     savestate = FALSE;
  571.     else savestate = TRUE;
  572. }
  573.  
  574.  
  575.  
  576. gvname(volnum)
  577. unsigned volnum;
  578. {
  579.     int    ccode;
  580.  
  581.     ccode = VolStat(volnum, &volinfo2);
  582.     if (ccode == 0 && volinfo2.vol_name[0] == 0) ccode = -1;
  583.     if (ccode) return (ccode);
  584.  
  585.     volinfo2.vol_name[15] = 0;
  586.     return (0);
  587. }
  588.  
  589. static    char    vselect[MAXVOLUMES];
  590.  
  591. getvollist()
  592. {
  593.     int    vol, count = 0;
  594.  
  595.     for (vol = 0; vol < MAXVOLUMES; vol++) {
  596.         if (gvname(vol) == 0) {
  597.             count++;
  598.             if (choosevol()) vselect[vol] = vol;
  599.             else vselect[vol] = 0xFF;
  600.         }
  601.         else vselect[vol] = 0xFF;
  602.     }
  603.  
  604.     if (!count) {
  605.         error("No system volumes on-line.\7");
  606.         myexit(0);
  607.     }
  608. }
  609.  
  610. choosevol()
  611. {
  612.     char    question[80];
  613.  
  614.     if (volinfo2.remove) sprintf(question, 
  615.         "Backup removable volume %s? (Y/N) ", volinfo2.vol_name);
  616.     else sprintf(question, 
  617.         "Backup   fixed   volume %s? (Y/N) ", volinfo2.vol_name);
  618.     return (yes(question));
  619. }
  620.  
  621. backupsys()
  622. {
  623.     int    vol;
  624.     char    volume[20];
  625.  
  626.     for (vol = 0; vol < MAXVOLUMES; vol++) {
  627.         if (vselect[vol] != 0xFF) {
  628.             if (gvname(vol) == 0) { /* make sure vol on-line */
  629.                 sprintf(volume, "%s:", volinfo2.vol_name);
  630.                 if (!setpath(VARPATH, volume)) {
  631.                     if (startup) {
  632.                         setup(); 
  633.                         startup = FALSE; 
  634.                         configlog();
  635.                         tapesetup();
  636.                         if (savestate) ssave ();
  637.                     }
  638.  
  639.                     /* BACKUP UP THIS ROOT */
  640.                     backupdir();
  641.  
  642.                     /* now do the subdirectories */
  643.                     showsub (1);
  644.                 }
  645.                 else cprintf ("\7Error accessing volume %s  --  skipping volume.\r\n", volume);
  646.             }
  647.         }
  648.     }
  649. }
  650.  
  651.  
  652. ssave ()
  653. {
  654.     ExFCB    search, file;
  655.     ExDirFCB    *dfile;
  656.     int    ccode, i;
  657.     char    savestring [260], f[16];
  658.  
  659.     getcurpath (VARPATH, savestring);
  660.  
  661.     strcpy (pathstring, "SYS:SUPER");
  662.  
  663.     if (!setpath (VARPATH, pathstring)) {
  664.         if (!checkrights (VARPATH, privmask)) {
  665.             if (printlog) printstr ("\r\n");
  666.             lprint ("SYS:SUPER\r\n     No backup privileges.\r\n");
  667.             return;
  668.         }
  669.         /* SEARCH FOR NET$PASS.SYS */
  670.         setmem (&search, sizeof (ExFCB), 0);
  671.         movmem ("NET$????SYS", search.fname, 11);
  672.         search.drive = VARPATH + 1;
  673.         search.exset = 0xFF;
  674.         search.flags = 0x02 | 0x04;
  675.         dfile = (ExDirFCB *) &file;
  676.         setDTA (&dfile->exset);
  677.  
  678.         ccode = search1 (&search.exset);
  679.         lprint ("\r\nSYS:SUPER\r\n");
  680.         if (ccode) {
  681.             lprint ("WARNING:  Files NET$PASS.SYS and/or NET$GRP.SYS not found!\r\n");
  682.             return;
  683.         }
  684.  
  685.         setmem (list, LISTSIZE*2, 0);
  686.         listcount = 0;
  687.  
  688.         while (ccode == 0) {
  689.             movmem (dfile->fname, f, 11);
  690.             f[11] = 0;
  691.             if (!strcmp("NET$PASSSYS",f) ||
  692.                 !strcmp("NET$GRP SYS",f)) addtolist (dfile);
  693.             setDTA (&dfile->exset);
  694.             ccode = searchn (&search.exset);
  695.         }
  696.         if (listcount != 2) {
  697.             lprint ("WARNING: Files NET$PASS.SYS and/or NET$GRP.SYS not found!\r\n");
  698.             for (i = 0; i < listcount; i++) {
  699.                 free (list [i]);
  700.             }
  701.             goto klugedone;
  702.         }
  703.  
  704.         AddTrustFile ();
  705.         writelist ();
  706.     }
  707. klugedone:
  708.     setpath (VARPATH, savestring);
  709. }
  710.